//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package gmapimagecutter;

import imagetoolscommon.Utils;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

public class GMICUtils {
    public GMICUtils() {
    }

    public static BufferedImage makeSingleTile(BufferedImage originalImage, boolean highQuality, String tileString, int zoomLevel, double x, double y, double width, double height) {
        if(zoomLevel >= tileString.length()) {
            BufferedImage centreX1 = new BufferedImage(256, 256, 1);
            Graphics2D g = centreX1.createGraphics();
            g.setPaint(Color.BLACK);
            g.fillRect(0, 0, 256, 256);
            if(highQuality) {
                BufferedImage centreY1 = Utils.get256pxScaledInstance(originalImage, (int)x, (int)y, (int)(x + width), (int)(y + height));
                g.drawImage(centreY1, 0, 0, (ImageObserver)null);
            } else {
                g.drawImage(originalImage, 0, 0, 256, 256, (int)x, (int)y, (int)(x + width), (int)(y + height), Color.black, (ImageObserver)null);
            }

            return centreX1;
        } else {
            double centreX = x + width / 2.0D;
            double centreY = y + height / 2.0D;
            switch(tileString.charAt(zoomLevel)) {
            case 'q':
                return makeSingleTile(originalImage, highQuality, tileString, zoomLevel + 1, x, y, width / 2.0D, height / 2.0D);
            case 'r':
                return makeSingleTile(originalImage, highQuality, tileString, zoomLevel + 1, centreX, y, width / 2.0D, height / 2.0D);
            case 's':
                return makeSingleTile(originalImage, highQuality, tileString, zoomLevel + 1, centreX, centreY, width / 2.0D, height / 2.0D);
            case 't':
                return makeSingleTile(originalImage, highQuality, tileString, zoomLevel + 1, x, centreY, width / 2.0D, height / 2.0D);
            default:
                return null;
            }
        }
    }
}
